package me.acomma.groot.interfaces.controller;

import me.acomma.groot.application.menu.*;
import me.acomma.groot.infrastructure.RestResult;
import me.acomma.groot.application.menu.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/menu")
public class MenuController {
    @Autowired
    private MenuApplicationService menuApplicationService;

    @GetMapping("/tree")
    public RestResult tree() {
        List<MenuData> tree = menuApplicationService.tree();
        return RestResult.success(tree);
    }

    @GetMapping("/detail")
    public RestResult detail(@RequestAttribute("menuId") Long menuId) {
        MenuData data = menuApplicationService.get(menuId);
        return RestResult.success(data);
    }

    @PostMapping("/create")
    public RestResult create(@RequestBody CreateMenuCommand command) {
        menuApplicationService.create(command);
        return RestResult.success();
    }

    @PostMapping("/modify")
    public RestResult modify(@RequestBody ModifyMenuCommand command) {
        menuApplicationService.modify(command);
        return RestResult.success();
    }

    @PostMapping("/remove")
    public RestResult remove(@RequestBody RemoveMenuCommand command) {
        menuApplicationService.remove(command);
        return RestResult.success();
    }
}
